home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MW MPW Binaries 1.1.1a2 / mwcPPC / MWCExamples / AboutBox ƒ / About.c next >
Encoding:
C/C++ Source or Header  |  1994-06-10  |  27.2 KB  |  805 lines  |  [TEXT/MPCC]

  1. /************************************************************************/
  2. /*  Project...: C++ and ANSI-C Compiler Environment                     */
  3. /*  Name......: MWAbout.c                                               */
  4. /*  Purpose...: about box                                               */
  5. /*  Copyright.: ©Copyright 1993 by metrowerks inc. All rights reserved. */
  6. /************************************************************************/
  7.  
  8. #include "About.h"
  9. #include <GestaltEqu.h>
  10. #include <QDOffscreen.h>
  11. #include <Sound.h>
  12.  
  13. #define     WIND_MetroAbout     1000
  14. #define     PICT_Background     1000
  15. #define     DITL_AboutItems     210
  16. #define     Item_Background     0
  17. #define     Item_BigBar         1
  18. #define     Item_SmallBar       2
  19. #define     Item_LogoBox        3
  20. #define     Item_NameBox        4
  21. #define     Item_CreditsBox     5
  22. #define     Item_BigBarShadow   6
  23. #define     Item_SmallBarShadow 7
  24. #define     PICT_BigBar         1001
  25. #define     PICT_BigBarShadow   2001
  26. #define     PICT_SmallBar       1002
  27. #define     PICT_SmallBarShadow 2002
  28. #define     PICT_LogoBox        3001
  29. #define     PICT_LogoHalf       3002
  30. #define     PICT_LogoWhole      3003
  31. #define     PICT_NameBox        3004
  32. #define     PICT_Credits        1004
  33. #define     snd_NameBoxClank    3004
  34. #define     Bounce_Distance     10
  35. #define     Fade_Levels         12
  36.  
  37. typedef struct UserItemRec  {
  38.     long padding1;
  39.     Rect box;
  40.     short padding2;
  41. } UserItemRec;
  42.  
  43. typedef struct DITLRec  {
  44.     short numItems;
  45.     UserItemRec theUserItems[1];
  46. } DITLRec, **DITLHand;
  47.  
  48. void DoAboutBox(void);
  49. void DoSimpleAbout(void);
  50. void SetUpGraphics(void);
  51. void DoAnimation(void);
  52. void CleanUpGraphics(void);
  53. void GetItemRect(short inItem, Rect *outRect);
  54. void DrawPictIntoNewGWorld(short inPICTid, short inDepth,
  55.                            GWorldPtr *outGWorldP);
  56.  
  57. typedef enum AnimateState  {
  58.     animate_Waiting,
  59.     animate_Active,
  60.     animate_Done
  61. } AnimateState;
  62.  
  63. void MoveOffWorld(GWorldPtr theGWorldP, Rect *currPos, Rect *newPos,
  64.                   Rect *imagePos);
  65. void MoveBar(GWorldPtr theGWorldP, GWorldPtr theShadowWorldP, Rect *inCurrPos,
  66.              Rect *inShadowPos, short inHorizOffset);
  67. void MoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset);
  68.  
  69. typedef struct BarRec  {
  70.     GWorldPtr theGWorldP;
  71.     GWorldPtr theShadowWorldP;
  72.     Rect currPos;
  73.     Rect shadowPos;
  74. } BarRec;
  75.  
  76. void SetUpBigBar(BarRec *inBigBarRec);
  77. void SetUpSmallBar(BarRec *inSmallBarRec);
  78.  
  79. typedef struct LogoRec  {
  80.     GWorldPtr theGWorldP;
  81.     Rect currPos;
  82.     Rect imagePos;
  83.     short bottomLoc;
  84. } LogoRec;
  85.  
  86. void SetUpLogoBox(LogoRec *inLogoBoxRec);
  87. void SetUpNameBox(LogoRec *inNameBoxRec);
  88.  
  89. typedef struct CreditsRec  {
  90.     GWorldPtr theGWorldP;
  91.     Rect viewRect;
  92.     Rect pictRect;
  93.     short pictHeight;
  94. } CreditsRec;
  95.  
  96. void SetUpCredits(CreditsRec *inCreditsRec);
  97.  
  98. static short Pixel_Depth;
  99. static CWindowPtr aboutBoxWindow;
  100. static PixMapPtr windowPixMapP;
  101. static GWorldPtr drawWorldP;
  102. static PixMapPtr drawPixMapP;
  103. static GWorldPtr backWorldP;
  104. static PixMapPtr backPixMapP;
  105.  
  106. void DoAboutBox(void)
  107. {
  108.     long qdVersion;
  109.     GWorldPtr saveWorld;
  110.     GDHandle saveDevice;
  111.  
  112.     Gestalt(gestaltQuickdrawVersion, &qdVersion);
  113.  
  114.     if ((qdVersion < gestalt32BitQD) || (FreeMem() < 350000)) {
  115.         GrafPtr savePort;
  116.         //    Machine lacks 32bit QuickDraw or there's not enough memory.
  117.         GetPort(&savePort);
  118.  
  119.         DoSimpleAbout();
  120.  
  121.         SetPort(savePort);
  122.  
  123.     } else {                //    OK to do animated about box.
  124.  
  125.         GetGWorld(&saveWorld, &saveDevice);
  126.  
  127.         SetUpGraphics();
  128.  
  129.         DoAnimation();
  130.  
  131.         CleanUpGraphics();
  132.  
  133.         PurgeMem(maxSize);
  134.         SetGWorld(saveWorld, saveDevice);
  135.     }
  136. }
  137.  
  138. static void DoSimpleAbout(void)
  139. {
  140.     WindowPtr macWindow = GetNewWindow(WIND_MetroAbout, nil, (WindowPtr) -1L);
  141.     PicHandle thePicture;
  142.     Rect r, picFrame;
  143.     long ticks;
  144.  
  145.     SetPort(macWindow);
  146.  
  147.     thePicture = GetPicture(PICT_Background);
  148.     if (thePicture != nil) {
  149.         r = (**thePicture).picFrame;
  150.  
  151.         DrawPicture(thePicture, &r);
  152.         ReleaseResource((Handle)thePicture);
  153.         Delay(45, &ticks);
  154.  
  155.         thePicture = GetPicture(PICT_LogoWhole);
  156.         GetItemRect(Item_LogoBox, &r);
  157.         DrawPicture(thePicture, &r);
  158.         ReleaseResource((Handle)thePicture);
  159.         Delay(45, &ticks);
  160.  
  161.         thePicture = GetPicture(PICT_NameBox);
  162.         GetItemRect(Item_NameBox, &r);
  163.         DrawPicture(thePicture, &r);
  164.         ReleaseResource((Handle)thePicture);
  165.         Delay(45, &ticks);
  166.  
  167.         thePicture = GetPicture(PICT_Credits);
  168.         picFrame = (**thePicture).picFrame;
  169.         GetItemRect(Item_CreditsBox, &r);
  170.         OffsetRect(&picFrame, r.left, r.top);
  171.         ClipRect(&r);
  172.         DrawPicture(thePicture, &picFrame);
  173.         ReleaseResource((Handle)thePicture);
  174.  
  175.         while (!Button())
  176.             ;
  177.     }
  178.     DisposeWindow(macWindow);
  179. }
  180.  
  181. static void SetUpGraphics(void)
  182. {
  183.     Rect backRect;
  184.     PixMapHandle thePixMapH;
  185.  
  186.     Pixel_Depth = 8;
  187.  
  188.     //    Make GWorld for offscreen drawing.
  189.  
  190.     GetItemRect(Item_Background, &backRect);
  191.     NewGWorld(&drawWorldP, Pixel_Depth, &backRect, nil, nil, 0);
  192.     thePixMapH = GetGWorldPixMap(drawWorldP);
  193.     HLockHi((Handle)thePixMapH);
  194.     LockPixels(thePixMapH);
  195.     drawPixMapP = *thePixMapH;
  196.  
  197.     //    Make GWorld for background.
  198.  
  199.     DrawPictIntoNewGWorld(PICT_Background, Pixel_Depth, &backWorldP);
  200.     thePixMapH = GetGWorldPixMap(backWorldP);
  201.     HLockHi((Handle)thePixMapH);
  202.     LockPixels(thePixMapH);
  203.     backPixMapP = *thePixMapH;
  204.  
  205.     //    Make Window.
  206.  
  207.     aboutBoxWindow = (CWindowPtr) GetNewCWindow(WIND_MetroAbout, nil,
  208.                                                 (WindowPtr) - 1L);
  209.     HLockHi((Handle)aboutBoxWindow->portPixMap);
  210.     windowPixMapP = *aboutBoxWindow->portPixMap;
  211.  
  212.     //    Draw background in Window.
  213.  
  214.     SetGWorld(aboutBoxWindow, GetMainDevice());
  215.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &backRect, &backRect, srcCopy, nil);
  216. }
  217.  
  218. void SetUpBigBar(BarRec *inBigBarRec)
  219. {
  220.     DrawPictIntoNewGWorld(PICT_BigBar, Pixel_Depth, &inBigBarRec->theGWorldP);
  221.     DrawPictIntoNewGWorld(PICT_BigBarShadow, Pixel_Depth,
  222.                           &inBigBarRec->theShadowWorldP);
  223.  
  224.     GetItemRect(Item_BigBar, &inBigBarRec->currPos);
  225.     GetItemRect(Item_BigBarShadow, &inBigBarRec->shadowPos);
  226.  
  227.     OffsetRect(&inBigBarRec->currPos, -inBigBarRec->shadowPos.right, 0);
  228.     OffsetRect(&inBigBarRec->shadowPos, -inBigBarRec->shadowPos.right, 0);
  229. }
  230.  
  231. void SetUpSmallBar(BarRec *inSmallBarRec)
  232. {
  233.     short barWidth;
  234.  
  235.     DrawPictIntoNewGWorld(PICT_SmallBar, Pixel_Depth,
  236.                           &inSmallBarRec->theGWorldP);
  237.     DrawPictIntoNewGWorld(PICT_SmallBarShadow, Pixel_Depth,
  238.                           &inSmallBarRec->theShadowWorldP);
  239.  
  240.     GetItemRect(Item_SmallBar, &inSmallBarRec->currPos);
  241.     GetItemRect(Item_SmallBarShadow, &inSmallBarRec->shadowPos);
  242.  
  243.     barWidth = inSmallBarRec->currPos.right - inSmallBarRec->currPos.left;
  244.  
  245.     inSmallBarRec->currPos.left = inSmallBarRec->currPos.right;
  246.     inSmallBarRec->currPos.right += barWidth;
  247.  
  248.     OffsetRect(&inSmallBarRec->shadowPos, barWidth, 0);
  249. }
  250.  
  251. void SetUpLogoBox(LogoRec *inLogoBoxRec)
  252. {
  253.     GetItemRect(Item_LogoBox, &inLogoBoxRec->currPos);
  254.     inLogoBoxRec->bottomLoc = inLogoBoxRec->currPos.bottom;
  255.     OffsetRect(&inLogoBoxRec->currPos, 0, -inLogoBoxRec->currPos.bottom);
  256. }
  257.  
  258. void SetUpNameBox(LogoRec *inNameBoxRec)
  259. {
  260.     DrawPictIntoNewGWorld(PICT_NameBox, Pixel_Depth,
  261.                           &inNameBoxRec->theGWorldP);
  262.  
  263.     GetItemRect(Item_NameBox, &inNameBoxRec->currPos);
  264.     inNameBoxRec->bottomLoc = inNameBoxRec->currPos.bottom;
  265.     OffsetRect(&inNameBoxRec->currPos, 0, -inNameBoxRec->currPos.bottom);
  266.     inNameBoxRec->imagePos.left = inNameBoxRec->imagePos.top = 0;
  267.     inNameBoxRec->imagePos.right = inNameBoxRec->currPos.right -
  268.         inNameBoxRec->currPos.left;
  269.     inNameBoxRec->imagePos.bottom = inNameBoxRec->currPos.bottom -
  270.         inNameBoxRec->currPos.top;
  271. }
  272.  
  273. void SetUpCredits(CreditsRec *inCreditsRec)
  274. {
  275.     PicHandle pictureH;
  276.     Rect picFrame;
  277.     PixMapHandle thePixMapH;
  278.  
  279.     //    The only animation is the credits
  280.     //  Therefore, we can reduce the size of the offscreen worlds for the background
  281.     //  and scratch drawing to just cover the area where the credits are drawn.
  282.  
  283.     DisposeGWorld(backWorldP);
  284.     DisposeGWorld(drawWorldP);
  285.  
  286.     GetItemRect(Item_CreditsBox, &inCreditsRec->viewRect);
  287.  
  288.     //    Make GWorld for offscreen drawing.
  289.  
  290.     NewGWorld(&drawWorldP, Pixel_Depth, &inCreditsRec->viewRect, nil, nil, 0);
  291.     thePixMapH = GetGWorldPixMap(drawWorldP);
  292.     HLockHi((Handle)thePixMapH);
  293.     LockPixels(thePixMapH);
  294.     drawPixMapP = *thePixMapH;
  295.  
  296.     //    Make GWorld for background.
  297.  
  298.     NewGWorld(&backWorldP, Pixel_Depth, &inCreditsRec->viewRect, nil,
  299.               GetGWorldDevice(drawWorldP), noNewDevice);
  300.     thePixMapH = GetGWorldPixMap(backWorldP);
  301.     HLockHi((Handle)thePixMapH);
  302.     LockPixels(thePixMapH);
  303.     backPixMapP = *thePixMapH;
  304.     SetGWorld(backWorldP, nil);
  305.     pictureH = GetPicture(PICT_Background);
  306.     picFrame = (**pictureH).picFrame;
  307.     DrawPicture(pictureH, &picFrame);
  308.     ReleaseResource((Handle)pictureH);
  309.  
  310.     //    Make GWorld for credits.
  311.  
  312.     DrawPictIntoNewGWorld(PICT_Credits, Pixel_Depth,
  313.                           &inCreditsRec->theGWorldP);
  314.  
  315.     inCreditsRec->pictRect.left = 0;
  316.     inCreditsRec->pictRect.top = 0;
  317.     inCreditsRec->pictRect.right = inCreditsRec->viewRect.right -
  318.         inCreditsRec->viewRect.left;
  319.     inCreditsRec->pictRect.bottom = inCreditsRec->viewRect.bottom -
  320.         inCreditsRec->viewRect.top;
  321.  
  322.     pictureH = GetPicture(PICT_Credits);
  323.     inCreditsRec->pictHeight = (**pictureH).picFrame.bottom;
  324.     ReleaseResource((Handle)pictureH);
  325. }
  326.  
  327. void MoveBar(GWorldPtr theGWorldP, GWorldPtr theShadowWorldP, Rect *inCurrPos,
  328.              Rect *inShadowPos, short inHorizOffset)
  329. {
  330.     Rect exposedRect, coveredRect, imageRect;
  331.     Rect shadowFront, shadowBack;
  332.     PixMapHandle offPixMapH;
  333.  
  334.     //    Draw to the Window.
  335.  
  336.     SetGWorld(aboutBoxWindow, GetMainDevice());
  337.  
  338.     //    Determine areas exposed and covered by bar as it moves.
  339.     
  340.     exposedRect = coveredRect = *inCurrPos;
  341.     shadowFront = shadowBack = *inShadowPos;
  342.     if (inHorizOffset > 0) {
  343.         exposedRect.right = exposedRect.left + inHorizOffset;
  344.         coveredRect.left = coveredRect.right;
  345.         coveredRect.right += inHorizOffset;
  346.         shadowBack.right = shadowBack.left + inHorizOffset;
  347.         shadowBack.top = coveredRect.bottom;
  348.         shadowFront.left = shadowFront.right;
  349.         shadowFront.right += inHorizOffset;
  350.     } else {
  351.         exposedRect.left = exposedRect.right + inHorizOffset;
  352.         exposedRect.bottom = shadowBack.top;
  353.         coveredRect.right = coveredRect.left;
  354.         coveredRect.left += inHorizOffset;
  355.         shadowBack.left = shadowBack.right + inHorizOffset;
  356.         shadowFront.right = shadowFront.left;
  357.         shadowFront.left += inHorizOffset;
  358.         shadowFront.top = coveredRect.bottom;
  359.     }
  360.     imageRect.left = coveredRect.left;
  361.     imageRect.right = coveredRect.right;
  362.     imageRect.top = 0;
  363.     imageRect.bottom = coveredRect.bottom - coveredRect.top;
  364.  
  365.     //    Restore background over exposed area.
  366.     
  367.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &exposedRect, &exposedRect, srcCopy,
  368.             nil);
  369.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &shadowBack, &shadowBack, srcCopy,
  370.             nil);
  371.  
  372.     //    Draw image at covered area.
  373.  
  374.     offPixMapH = GetGWorldPixMap(theGWorldP);
  375.     LockPixels(offPixMapH);
  376.     CopyBits ((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &imageRect, &coveredRect, srcCopy,
  377.              nil);
  378.     UnlockPixels(offPixMapH);
  379.  
  380.     offPixMapH = GetGWorldPixMap(theShadowWorldP);
  381.     LockPixels(offPixMapH);
  382.     CopyBits ((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &shadowFront, &shadowFront, srcCopy,
  383.              nil);
  384.     if (inHorizOffset < 0) {
  385.         shadowFront.left = exposedRect.left;
  386.         shadowFront.right = exposedRect.right;
  387.         shadowFront.top = shadowBack.top;
  388.         CopyBits ((BitMapPtr)(*offPixMapH), (BitMapPtr)windowPixMapP, &shadowFront, &shadowFront,
  389.                  srcCopy, nil);
  390.     }
  391.     UnlockPixels(offPixMapH);
  392. }
  393.  
  394. void MoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset)
  395. {
  396.     Rect exposedRect, coveredRect, imageRect;
  397.     RGBColor boxColor =  {
  398.         65535, 52428, 0
  399.     };
  400.  
  401.     //    Draw to the Window.
  402.  
  403.     SetGWorld(aboutBoxWindow, GetMainDevice());
  404.  
  405.     //    Determine areas exposed and covered by bar as it moves.
  406.     
  407.     exposedRect = coveredRect = *inCurrPos;
  408.     if (inVertOffset > 0) {
  409.         exposedRect.bottom = exposedRect.top + inVertOffset;
  410.         coveredRect.top = coveredRect.bottom;
  411.         coveredRect.bottom += inVertOffset;
  412.     } else {
  413.         exposedRect.top = exposedRect.bottom + inVertOffset;
  414.         coveredRect.bottom = coveredRect.top;
  415.         coveredRect.top += inVertOffset;
  416.     }
  417.     imageRect.left = 0;
  418.     imageRect.right = coveredRect.right - coveredRect.left;
  419.     imageRect.top = 0;
  420.     imageRect.bottom = coveredRect.bottom - coveredRect.top;
  421.  
  422.     //    Restore background over exposed area.
  423.     
  424.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)windowPixMapP, &exposedRect, &exposedRect, srcCopy,
  425.             nil);
  426.  
  427.     //    Draw image at covered area.
  428.  
  429.     RGBForeColor(&boxColor);
  430.     PaintRect(&coveredRect);
  431.     ForeColor(blackColor);
  432. }
  433.  
  434. void MoveOffWorld(GWorldPtr theGWorldP, Rect *inCurrPos, Rect *inNewPos,
  435.                   Rect *inOffPos)
  436. {
  437.     Rect drawRect;
  438.     PixMapHandle offPixMapH;
  439.  
  440.     //    Create image in draw world.
  441.  
  442.     SetGWorld(drawWorldP, nil);
  443.  
  444.     //    Restore background at current position.
  445.     
  446.     CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP, inCurrPos, inCurrPos, srcCopy, nil);
  447.  
  448.     //    Draw image at new position.
  449.     
  450.     offPixMapH = GetGWorldPixMap(theGWorldP);
  451.     LockPixels(offPixMapH);
  452.     CopyBits ((BitMapPtr)(*offPixMapH), (BitMapPtr)drawPixMapP, inOffPos, inNewPos, srcCopy, nil);
  453.     UnlockPixels(offPixMapH);
  454.  
  455.     //    Draw union of old and new position to Window.
  456.     
  457.     SetGWorld(aboutBoxWindow, GetMainDevice());
  458.     UnionRect(inCurrPos, inNewPos, &drawRect);
  459.     CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP, &drawRect, &drawRect, srcCopy, nil);
  460. }
  461.  
  462. static void DoAnimation(void)
  463. {
  464.     BarRec theBigBarRec;
  465.     BarRec theSmallBarRec;
  466.     LogoRec theLogoBoxRec;
  467.     LogoRec theNameBoxRec;
  468.     CreditsRec theCreditsRec;
  469.  
  470.     Rect currPos, imagePos;
  471.  
  472.     PicHandle thePictureH;
  473.     SndChannelPtr theSoundChannelP = nil;
  474.     Handle theSoundH = nil;
  475.  
  476.     AnimateState animBigBar = animate_Active;
  477.     AnimateState animSmallBar = animate_Waiting;
  478.     AnimateState animLogoBoxDown = animate_Waiting;
  479.     AnimateState animLogoBoxUp = animate_Waiting;
  480.     AnimateState animNameBoxDown = animate_Waiting;
  481.     AnimateState animNameBoxUp = animate_Waiting;
  482.     AnimateState animCreditsFade = animate_Waiting;
  483.     AnimateState animCreditsScroll = animate_Waiting;
  484.  
  485.     Boolean logoHalfDrawn = false;
  486.     Boolean logoWholeDrawn = false;
  487.  
  488.     RGBColor fadeColor;
  489.     short grayIndex = 0;
  490.     unsigned short grayLevels[Fade_Levels] =  {
  491.         4369, 8738, 17476, 21845, 30583, 34952, 43690, 48059, 52428, 56979,
  492.         61166, 65535
  493.     };
  494.  
  495.     theBigBarRec.theGWorldP = nil;
  496.     theBigBarRec.theShadowWorldP = nil;
  497.     theSmallBarRec.theGWorldP = nil;
  498.     theSmallBarRec.theShadowWorldP = nil;
  499.     theLogoBoxRec.theGWorldP = nil;
  500.     theNameBoxRec.theGWorldP = nil;
  501.     theCreditsRec.theGWorldP = nil;
  502.  
  503.     SetUpBigBar(&theBigBarRec);
  504.     SetUpLogoBox(&theLogoBoxRec);
  505.     theSoundH = GetResource('snd ', snd_NameBoxClank);
  506.     theSmallBarRec.currPos.left = 1000;
  507.  
  508.     while (!Button()) {
  509.         long ticks;
  510.         long endTicks;
  511.         long startTicks = TickCount();
  512.  
  513.         if ((animLogoBoxDown == animate_Waiting) &&
  514.             (theBigBarRec.currPos.left > 100)) {
  515.             animLogoBoxDown = animate_Active;
  516.         }
  517.         if ((animLogoBoxDown == animate_Active) &&
  518.             (theLogoBoxRec.currPos.bottom >=
  519.              theLogoBoxRec.bottomLoc + Bounce_Distance)) {
  520.             animLogoBoxDown = animate_Done;
  521.             animLogoBoxUp = animate_Active;
  522.         }
  523.         if ((animLogoBoxUp == animate_Active) &&
  524.             (theLogoBoxRec.currPos.bottom <= theLogoBoxRec.bottomLoc)) {
  525.             animLogoBoxUp = animate_Done;
  526.         }
  527.         if ((animBigBar == animate_Active) && !logoHalfDrawn &&
  528.             (theBigBarRec.currPos.right > theLogoBoxRec.currPos.right)) {
  529.             SetGWorld(backWorldP, nil);
  530.             thePictureH = GetPicture(PICT_LogoHalf);
  531.             DrawPicture(thePictureH, &theLogoBoxRec.currPos);
  532.             ReleaseResource((Handle)thePictureH);
  533.             logoHalfDrawn = true;
  534.         }
  535.         if ((animBigBar == animate_Active) &&
  536.             theBigBarRec.currPos.left > backWorldP->portRect.right) {
  537.             animBigBar = animate_Done;
  538.             DisposeGWorld(theBigBarRec.theGWorldP);
  539.             theBigBarRec.theGWorldP = nil;
  540.             DisposeGWorld(theBigBarRec.theShadowWorldP);
  541.             theBigBarRec.theShadowWorldP = nil;
  542.             animSmallBar = animate_Active;
  543.             SetUpSmallBar(&theSmallBarRec);
  544.         }
  545.         if ((animSmallBar == animate_Active) && !logoWholeDrawn &&
  546.             (theSmallBarRec.currPos.left < theLogoBoxRec.currPos.left)) {
  547.             SetGWorld(backWorldP, nil);
  548.             thePictureH = GetPicture(PICT_LogoWhole);
  549.             DrawPicture(thePictureH, &theLogoBoxRec.currPos);
  550.             ReleaseResource((Handle)thePictureH);
  551.             logoWholeDrawn = true;
  552.         }
  553.         if ((animNameBoxDown == animate_Waiting) &&
  554.             (theSmallBarRec.currPos.left < 150)) {
  555.             animNameBoxDown = animate_Active;
  556.             SetUpNameBox(&theNameBoxRec);
  557.         }
  558.         if ((animNameBoxDown == animate_Active) &&
  559.             (theNameBoxRec.currPos.bottom >=
  560.              theNameBoxRec.bottomLoc + Bounce_Distance)) {
  561.             animNameBoxDown = animate_Done;
  562.             animNameBoxUp = animate_Active;
  563.         }
  564.         if ((animNameBoxUp == animate_Active) &&
  565.             (theNameBoxRec.currPos.bottom <= theNameBoxRec.bottomLoc)) {
  566.             OSErr err;
  567.             animNameBoxUp = animate_Done;
  568.             DisposeGWorld(theNameBoxRec.theGWorldP);
  569.             theNameBoxRec.theGWorldP = nil;
  570.             if (theSoundH != nil) {
  571.                 err = SndNewChannel(&theSoundChannelP, sampledSynth, initMono,
  572.                                     nil);
  573.                 if (err == noErr)
  574.                     SndPlay(theSoundChannelP, theSoundH, true);
  575.             }
  576.         }
  577.         if ((animSmallBar == animate_Active) &&
  578.             (theSmallBarRec.shadowPos.right < backWorldP->portRect.left)) {
  579.             animSmallBar = animate_Done;
  580.             DisposeGWorld(theSmallBarRec.theGWorldP);
  581.             theSmallBarRec.theGWorldP = nil;
  582.             DisposeGWorld(theSmallBarRec.theShadowWorldP);
  583.             theSmallBarRec.theShadowWorldP = nil;
  584.  
  585.             if (theSoundChannelP != nil) {
  586.                 SndDisposeChannel(theSoundChannelP, true);
  587.                 theSoundChannelP = nil;
  588.             }
  589.             if (theSoundH != nil) {
  590.                 ReleaseResource(theSoundH);
  591.                 theSoundH = nil;
  592.             }
  593.             animCreditsFade = animate_Active;
  594.             SetUpCredits(&theCreditsRec);
  595.         }
  596.         if ((animCreditsFade == animate_Active) &&
  597.             (grayIndex >= Fade_Levels)) {
  598.             animCreditsFade = animate_Done;
  599.             Delay(90, &ticks);
  600.             animCreditsScroll = animate_Active;
  601.         }
  602.         if ((animCreditsScroll == animate_Active) &&
  603.             (theCreditsRec.pictRect.top > theCreditsRec.pictHeight)) {
  604.             theCreditsRec.pictRect.top = 1;
  605.             theCreditsRec.pictRect.bottom = theCreditsRec.viewRect.bottom -
  606.                 theCreditsRec.viewRect.top + 1;
  607.         }
  608.         if (animBigBar == animate_Active) {
  609.             MoveBar(theBigBarRec.theGWorldP, theBigBarRec.theShadowWorldP,
  610.                     &theBigBarRec.currPos, &theBigBarRec.shadowPos, 1);
  611.             theBigBarRec.currPos.left++;
  612.             theBigBarRec.currPos.right++;
  613.             theBigBarRec.shadowPos.left++;
  614.             theBigBarRec.shadowPos.right++;
  615.         }
  616.         if (animLogoBoxDown == animate_Active) {
  617.             MoveLogoBox(theLogoBoxRec.theGWorldP, &theLogoBoxRec.currPos, 1);
  618.             theLogoBoxRec.currPos.top++;
  619.             theLogoBoxRec.currPos.bottom++;
  620.         }
  621.         if (animLogoBoxUp == animate_Active) {
  622.             MoveLogoBox(theLogoBoxRec.theGWorldP, &theLogoBoxRec.currPos, -1);
  623.             theLogoBoxRec.currPos.top--;
  624.             theLogoBoxRec.currPos.bottom--;
  625.         }
  626.         if (animSmallBar == animate_Active) {
  627.             MoveBar(theSmallBarRec.theGWorldP, theSmallBarRec.theShadowWorldP,
  628.                     &theSmallBarRec.currPos, &theSmallBarRec.shadowPos, -1);
  629.             theSmallBarRec.currPos.left--;
  630.             theSmallBarRec.currPos.right--;
  631.             theSmallBarRec.shadowPos.left--;
  632.             theSmallBarRec.shadowPos.right--;
  633.         }
  634.         if (animNameBoxDown == animate_Active) {
  635.             currPos = theNameBoxRec.currPos;
  636.             theNameBoxRec.currPos.top++;
  637.             theNameBoxRec.currPos.bottom++;
  638.             imagePos = theNameBoxRec.imagePos;
  639.             MoveOffWorld(theNameBoxRec.theGWorldP, &currPos,
  640.                          &theNameBoxRec.currPos, &imagePos);
  641.         }
  642.         if (animNameBoxUp == animate_Active) {
  643.             currPos = theNameBoxRec.currPos;
  644.             theNameBoxRec.currPos.top--;
  645.             theNameBoxRec.currPos.bottom--;
  646.             imagePos = theNameBoxRec.imagePos;
  647.             MoveOffWorld(theNameBoxRec.theGWorldP, &currPos,
  648.                          &theNameBoxRec.currPos, &imagePos);
  649.         }
  650.         if (animCreditsFade == animate_Active) {
  651.             PixMapHandle thePixMapH;
  652.  
  653.             Delay(3, &ticks);
  654.             SetGWorld(drawWorldP, nil);
  655.  
  656.             thePixMapH = GetGWorldPixMap(theCreditsRec.theGWorldP);
  657.             LockPixels(thePixMapH);
  658.             CopyBits ((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP, &theCreditsRec.pictRect,
  659.                      &theCreditsRec.viewRect, srcCopy, nil);
  660.             UnlockPixels(thePixMapH);
  661.  
  662.             fadeColor.red = fadeColor.blue = fadeColor.green =
  663.                 grayLevels[grayIndex++];
  664.             RGBForeColor(&fadeColor);
  665.             PenMode(adMin);
  666.             PaintRect(&theCreditsRec.viewRect);
  667.             PenMode(patCopy);
  668.             ForeColor(blackColor);
  669.  
  670.             CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP, &theCreditsRec.viewRect,
  671.                     &theCreditsRec.viewRect, adMax, nil);
  672.  
  673.             SetGWorld(aboutBoxWindow, GetMainDevice());
  674.             CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP, &theCreditsRec.viewRect,
  675.                     &theCreditsRec.viewRect, srcCopy, nil);
  676.         }
  677.         if (animCreditsScroll == animate_Active) {
  678.             PixMapHandle thePixMapH;
  679.             short i, j;
  680.             short creditsWidth =
  681.                 theCreditsRec.viewRect.right -theCreditsRec.viewRect.left -1;
  682.             Rect wrapViewRect, wrapPictRect;
  683.  
  684.             SetGWorld(drawWorldP, nil);
  685.  
  686.             theCreditsRec.pictRect.top += 1;
  687.             theCreditsRec.pictRect.bottom += 1;
  688.  
  689.             thePixMapH = GetGWorldPixMap(theCreditsRec.theGWorldP);
  690.             LockPixels(thePixMapH);
  691.             if (theCreditsRec.pictRect.bottom <= theCreditsRec.pictHeight) {
  692.                 CopyBits ((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP, &theCreditsRec.pictRect,
  693.                          &theCreditsRec.viewRect, srcCopy, nil);
  694.             } else {
  695.                 wrapViewRect = theCreditsRec.viewRect;
  696.                 wrapViewRect.top = wrapViewRect.bottom -
  697.                     (theCreditsRec.pictRect.bottom -
  698.                      theCreditsRec.pictHeight);
  699.                 wrapPictRect = theCreditsRec.pictRect;
  700.                 wrapPictRect.top = 0;
  701.                 wrapPictRect.bottom = wrapPictRect.top +
  702.                     (wrapViewRect.bottom - wrapViewRect.top);
  703.                 CopyBits ((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP, &theCreditsRec.pictRect,
  704.                          &theCreditsRec.viewRect, srcCopy, nil);
  705.                 CopyBits ((BitMapPtr)(*thePixMapH), (BitMapPtr)drawPixMapP, &wrapPictRect,
  706.                          &wrapViewRect, srcCopy, nil);
  707.             }
  708.             UnlockPixels(thePixMapH);
  709.  
  710.             PenMode(adMin);
  711.             j = Fade_Levels - 1;
  712.             for (i = 0; i < j; i++) {
  713.                 fadeColor.red = fadeColor.blue = fadeColor.green =
  714.                     grayLevels[i];
  715.                 RGBForeColor(&fadeColor);
  716.                 MoveTo(theCreditsRec.viewRect.left,
  717.                        theCreditsRec.viewRect.top + i);
  718.                 Line(creditsWidth, 0);
  719.                 MoveTo(theCreditsRec.viewRect.left,
  720.                        theCreditsRec.viewRect.bottom - i - 1);
  721.                 Line(creditsWidth, 0);
  722.             }
  723.             ForeColor(blackColor);
  724.             PenMode(patCopy);
  725.  
  726.             CopyBits((BitMapPtr)backPixMapP, (BitMapPtr)drawPixMapP, &theCreditsRec.viewRect,
  727.                     &theCreditsRec.viewRect, adMax, nil);
  728.             SetGWorld(aboutBoxWindow, GetMainDevice());
  729.             CopyBits((BitMapPtr)drawPixMapP, (BitMapPtr)windowPixMapP, &theCreditsRec.viewRect,
  730.                     &theCreditsRec.viewRect, srcCopy, nil);
  731.         }
  732.         endTicks = TickCount(); //    Timing loop.
  733.         if (endTicks == startTicks) {   //    TickCount must change during each pass thru animation loop.
  734.             while (endTicks == TickCount())
  735.                 ;           //    this puts an upper speed limit on the animation rate.
  736.         }
  737.     }
  738.  
  739.     // Finished animation (user clicked). Flush the mousedown events
  740.  
  741.     FlushEvents(mDownMask | mUpMask | keyDownMask | keyUpMask | autoKeyMask,0);
  742.  
  743.     //    Dispose of all GWorlds (if they haven't already been disposed).
  744.  
  745.     if (theBigBarRec.theGWorldP != nil)
  746.         DisposeGWorld(theBigBarRec.theGWorldP);
  747.     if (theBigBarRec.theShadowWorldP != nil)
  748.         DisposeGWorld(theBigBarRec.theShadowWorldP);
  749.     if (theSmallBarRec.theGWorldP != nil)
  750.         DisposeGWorld(theSmallBarRec.theGWorldP);
  751.     if (theSmallBarRec.theShadowWorldP != nil)
  752.         DisposeGWorld(theSmallBarRec.theShadowWorldP);
  753.     if (theLogoBoxRec.theGWorldP != nil)
  754.         DisposeGWorld(theLogoBoxRec.theGWorldP);
  755.     if (theNameBoxRec.theGWorldP != nil)
  756.         DisposeGWorld(theNameBoxRec.theGWorldP);
  757.     if (theCreditsRec.theGWorldP != nil)
  758.         DisposeGWorld(theCreditsRec.theGWorldP);
  759.  
  760.     if (theSoundChannelP != nil)
  761.         SndDisposeChannel(theSoundChannelP, true);
  762.     if (theSoundH != nil)
  763.         ReleaseResource(theSoundH);
  764. }
  765.  
  766. static void CleanUpGraphics(void)
  767. {
  768.     DisposeGWorld(drawWorldP);
  769.     DisposeGWorld(backWorldP);
  770.     DisposeWindow((WindowPtr)aboutBoxWindow);
  771. }
  772.  
  773. void GetItemRect(short inItem, Rect *outRect)
  774. {
  775.     DITLHand theDITL;
  776.  
  777.     theDITL = (DITLHand) GetResource('DITL', DITL_AboutItems);
  778.     *outRect = (**theDITL).theUserItems[inItem].box;
  779. }
  780.  
  781. void DrawPictIntoNewGWorld(short inPICTid, short inDepth,
  782.                            GWorldPtr *outGWorldP)
  783. {
  784.     PicHandle thePicture;
  785.     Rect picFrame;
  786.     GWorldPtr saveWorld;
  787.     GDHandle saveDevice;
  788.     OSErr err;
  789.  
  790.     thePicture = GetPicture(inPICTid);
  791.     picFrame = (**thePicture).picFrame;
  792.  
  793.     err = NewGWorld(outGWorldP, inDepth, &picFrame, nil,
  794.                     GetGWorldDevice(drawWorldP), noNewDevice);
  795.     if (err != noErr)
  796.         Debugger();
  797.  
  798.     GetGWorld(&saveWorld, &saveDevice);
  799.     SetGWorld (*outGWorldP, nil);
  800.     DrawPicture(thePicture, &picFrame);
  801.     SetGWorld(saveWorld, saveDevice);
  802.  
  803.     ReleaseResource((Handle)thePicture);
  804. }
  805.